#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int MOD;
typedef vector<ll> vi;
struct Mat {
  int r, c;
  vector<vi> f;
  Mat(int r, int c = 1) : r(r), c(c), f(r + 1, vi(c + 1)) {}
  Mat operator*(const Mat &b) const {
    assert(c == b.r);
    Mat m(r, b.c);
    for (int i = 1; i <= r; ++i)
      for (int j = 1; j <= b.c; ++j)
        for (int k = 1; k <= c; ++k)
          (m.f[i][j] += f[i][k] * b.f[k][j] % MOD) %= MOD;
    return m;
  }
  Mat operator^(ll b) {
    Mat g = *this, m = *this;
    assert(r == c);
    for (--b; b > 0; b >>= 1, g = g * g)
      if (b & 1) m = m * g;
    return m;
  }
};
int main() {
  for (int d, n, m; cin >> d >> n >> m && d;) {
    vi a(d + 1);
    Mat f(d), A(d, d);
    for (int i = 1; i <= d; ++i) {
      cin >> a[i], a[i] %= m, A.f[1][i] = a[i];
      if (i > 1) A.f[i][i - 1] = 1;
    }
    MOD = m;
    for (int i = 1; i <= d; ++i) cin >> f.f[d - n + 1][1];
    if (n <= d) {
      cout << f.f[d - n + 1][1] << endl;
      continue;
    }
    Mat ans = (A ^ (n - d)) * f;
    cout << ans.f[1][1] << endl;
  }
}
